<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="com.gzsz.util.DBUtil" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
String id=request.getParameter("id");
PreparedStatement pstmt = null;
ResultSet resultSet = null;
DBUtil dbUtil=new DBUtil();
String sql="select * from paiban where id="+id+";";
pstmt = dbUtil.getConnection().prepareStatement(sql);
resultSet = pstmt.executeQuery();

String employee_name = "";
String occupation = "";
String schedule_date = "";
String shift_type = "";
String start_time = "";
String end_time = "";

if (id == null) {
    id = "";
}

while (resultSet.next()) {
    employee_name = resultSet.getString("employee_name");
    occupation = resultSet.getString("occupation");
    schedule_date = resultSet.getString("schedule_date");
    shift_type = resultSet.getString("shift_type");
    start_time = resultSet.getString("start_time");
    end_time = resultSet.getString("end_time");
}
%>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加信息</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            margin: 0;
            margin-bottom: 200px;
        }

        form {
            background-color: #fff;
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
            width: 400px;
        }

        label {
            display: block;
            margin-bottom: 5px;
        }

        input,
        select,
        textarea {
            width: 100%;
            padding: 6px;
            /*内边距*/
            margin-bottom: 10px;
            /*元素之间的间距*/
            border: 1px solid #ccc;
            border-radius: 3px;
        }
        textarea {
            height: 40px;
            /*设置文本域高度*/
        }

        input[type="submit"] {
            background-color: #007BFF;
            cursor: pointer;
        }

        input[type="submit"]:hover {
            background-color: #0056b3;
        }
    </style>
</head>

<body>
<form action="GETpaibanguanli.jsp" method="get" accept-charset="UTF-8">
    <% if (id == null || id.isEmpty()) { %>
        <h2>添加信息</h2>
    <% } else {%>
        <h2>修改信息</h2>
    <% } %>
    <label for="id"></label>
    <input value="<%=id%>" hidden type="text" id="id" name="id">

    <label for="employee_name">姓名:</label>
    <input value="<%=employee_name%>" type="text" id="employee_name" name="employee_name" required>

    <label for="occupation">职称:</label>
    <input value="<%=occupation%>" type="text" id="occupation" name="occupation" required>

    <label for="schedule_date">值班日期:</label>
    <input value="<%=schedule_date%>" type="date" id="schedule_date" name="schedule_date">

    <label for="shift_type">班次类型:</label>
    <select id="shift_type" name="shift_type" required>
        <option value="早班">早班</option>
        <option value="中班">中班</option>
        <option value="晚班">晚班</option>
    </select>

    <label for="start_time">开始时间:</label>
    <input value="<%=start_time%>" type="text" id="start_time" name="start_time" required>

    <label for="end_time">结束时间:</label>
    <input value="<%=end_time%>" type="text" id="end_time" name="end_time" required>

    <input type="submit" value="提交">
</form>
</body>
<script>
    const shift_type = document.getElementById("shift_type");
    const options = shift_type.getElementsByTagName("option");
    console.log(options)
    for (const opt of options) {
        console.log(opt)
        if (opt.value == "<%=shift_type%>") {
            opt.setAttribute("selected", true);
            break;
        }
    }
</script>
</html>

